package com.wanmait.myhouse.webController;

import com.wanmait.myhouse.dao.HouseDAO;
import com.wanmait.myhouse.vo.House;
import com.wanmait.myhouse.vo.Pager;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("web")
public class WebBuySingleController {
    @GetMapping("buySingle")
    public String buySingle(Integer pno , Model model,House house){
        if ("选择城市".equals(house.getCity()) || "".equals(house.getCity())){
            house.setCity(null);
        }
        if ("选择类别".equals(house.getType()) || "".equals(house.getType())){
            house.setType(null);
        }
        if ("卧室数量".equals(house.getRoom()) || "".equals(house.getRoom())){
            house.setRoom(null);
        }
        HouseDAO houseDAO = new HouseDAO();
        Pager pager = new Pager();

        if (pno==null){
            pno=1;
        }
        pager.setPageNO(pno);
        pager.setPageSize(4);
        int total = houseDAO.getTotal(house,2);
        Integer pageCount = total/ pager.getPageSize()+(total% pager.getPageSize()==0?0:1);
        pager.setPageCount(pageCount);
        model.addAttribute("paper",pager);
        List<House> houseList = houseDAO.FindPagerFall(pager, 2, house);
        model.addAttribute("HouseList",houseList);
        return "web/buy_single";
    }
}